package com.pureut.equipment.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pureut.equipment.domain.dto.MaintenanceProjectDto;
import com.pureut.equipment.domain.vo.MaintenanceProjectVo;
import com.pureut.equipment.service.MaintenanceProjectService;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/***
 *
 * Author: 保养项目控制层
 * Date:2023/04/23 13:10
 * @DESC
 */
@RestController
@RequestMapping("/maintenance-project")
public class MaintenanceProjectController extends BaseController {

    /**
     * 保养项目service
     */
    @Resource
    MaintenanceProjectService maintenanceProjectService;

    /**
     * 保养项目列表
     */
    @SaCheckPermission("device:maintenance:project:list")
    @GetMapping("/list")
    public TableDataInfo<MaintenanceProjectDto> list(MaintenanceProjectVo maintenanceProjectVo, PageQuery pageQuery) {
        return maintenanceProjectService.getList(maintenanceProjectVo, pageQuery);
    }

    /**
     * 新增
     */
    @SaCheckPermission("device:maintenance:project:add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody MaintenanceProjectVo maintenanceProjectVo) throws Exception {
        return toAjax(maintenanceProjectService.add(maintenanceProjectVo));
    }

    /**
     * 删除
     */
    @SaCheckPermission("device:maintenance:project:remove")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{id}")
    public R<Void> removeMaintenanceProject(@PathVariable("id") Long id) {
        return toAjax(maintenanceProjectService.deleteMaintenanceProjectById(id));
    }

    /**
     * 查看
     */
    @SaCheckPermission("device:maintenance:project:query")
    @GetMapping("/getView/{id}")
    public R<MaintenanceProjectDto> getView(@PathVariable("id") Long id) {
        return R.ok(maintenanceProjectService.getView(id));
    }

    /**
     * 修改
     */
    @SaCheckPermission("device:maintenance:project:edit")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public R<Void> update(@RequestBody MaintenanceProjectVo maintenanceProjectVo) {
        return toAjax(maintenanceProjectService.updateMaintenanceProject(maintenanceProjectVo));
    }
}
